package lnk

import (
	"encoding/binary"
	"fmt"
)

// GUID https://docs.microsoft.com/en-us/previous-versions/aa373931(v=vs.80)
type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]uint8
}

func (this GUID) String() string {
	const FormatString = "%08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X"
	a := this.Data4[0]
	b := this.Data4[1]
	u := uint16(a)<<8 | uint16(b)
	return fmt.Sprintf(FormatString, this.Data1, this.Data2, this.Data3, u,
		this.Data4[2], this.Data4[3], this.Data4[4],
		this.Data4[5], this.Data4[6], this.Data4[7])
}

func makeGuidWithBytes(data [16]byte) (guid GUID) {
	guid.Data1 = binary.BigEndian.Uint32(data[:4])
	guid.Data2 = binary.BigEndian.Uint16(data[4:6])
	guid.Data3 = binary.BigEndian.Uint16(data[6:8])
	copy(guid.Data4[:], data[8:16])
	//guid.Data4 = [8]uint8([]uint8(data[11:]))
	return
}
